home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gp_iwatc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.1 KB  |  155 lines

  1. /* Copyright (C) 1991, 1995, 1998, 1999, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gp_iwatc.c,v 1.4 2000/09/19 19:00:24 lpd Exp $ */
  20. /* Intel processor, Watcom C-specific routines for Ghostscript */
  21. #include "dos_.h"
  22. #include <fcntl.h>
  23. #include <signal.h>
  24. #include <stdlib.h>
  25. #include "stat_.h"
  26. #include "string_.h"
  27. #include "gx.h"
  28. #include "gp.h"
  29. #include "gpmisc.h"
  30.  
  31. /* Library routines not declared in a standard header */
  32. extern char *mktemp(P1(char *));    /* in gp_mktmp.c */
  33.  
  34. /* Define a substitute for stdprn (see below). */
  35. private FILE *gs_stdprn;
  36.  
  37. /* Forward declarations */
  38. private void handle_FPE(P1(int));
  39.  
  40. /* Do platform-dependent initialization. */
  41. void
  42. gp_init(void)
  43. {
  44.     gs_stdprn = 0;
  45.     /* Set up the handler for numeric exceptions. */
  46.     signal(SIGFPE, handle_FPE);
  47. }
  48.  
  49. /* Trap numeric exceptions.  Someday we will do something */
  50. /* more appropriate with these. */
  51. private void
  52. handle_FPE(int sig)
  53. {
  54.     eprintf("Numeric exception:\n");
  55.     exit(1);
  56. }
  57.  
  58. /* Do platform-dependent cleanup. */
  59. void
  60. gp_exit(int exit_status, int code)
  61. {
  62. }
  63.  
  64. /* Exit the program. */
  65. void
  66. gp_do_exit(int exit_status)
  67. {
  68.     exit(exit_status);
  69. }
  70.  
  71. /* ------ Printer accessing ------ */
  72.  
  73. /* Open a connection to a printer.  A null file name means use the */
  74. /* standard printer connected to the machine, if any. */
  75. /* Return NULL if the connection could not be opened. */
  76. extern void gp_set_file_binary(P2(int, int));
  77. FILE *
  78. gp_open_printer(char fname[gp_file_name_sizeof], int binary_mode)
  79. {
  80.     FILE *pfile;
  81.  
  82.     if (strlen(fname) == 0 || !strcmp(fname, "PRN")) {
  83. #ifdef stdprn
  84.     if (!binary_mode)
  85.         return stdprn;
  86.     if (gs_stdprn == 0) {
  87.         /* We have to effectively reopen the printer, */
  88.         /* because the Watcom library does \n -> \r\n */
  89.         /* substitution on the stdprn stream. */
  90.         int fno = dup(fileno(stdprn));
  91.  
  92.         setmode(fno, O_BINARY);
  93.         gs_stdprn = fdopen(fno, "wb");
  94.     }
  95.     pfile = gs_stdprn;
  96. #else    /* WATCOM doesn't know about stdprn device */
  97.     pfile = fopen("PRN", (binary_mode ? "wb" : "w"));
  98.     if (pfile == NULL)
  99.         return NULL;
  100. #endif    /* defined(stdprn) */
  101.     } else {
  102.     pfile = fopen(fname, (binary_mode ? "wb" : "w"));
  103.     if (pfile == NULL)
  104.         return NULL;
  105.     }
  106.     gp_set_file_binary(fileno(pfile), binary_mode);
  107.     return pfile;
  108. }
  109.  
  110. /* Close the connection to the printer. */
  111. void
  112. gp_close_printer(FILE * pfile, const char *fname)
  113. {
  114. #ifdef stdprn
  115.     if (pfile != stdprn)
  116. #endif    /* defined(stdprn) */
  117.     fclose(pfile);
  118.     if (pfile == gs_stdprn)
  119.     gs_stdprn = 0;
  120. }
  121.  
  122. /* ------ File naming and accessing ------ */
  123.  
  124. /* Create and open a scratch file with a given name prefix. */
  125. /* Write the actual file name at fname. */
  126. FILE *
  127. gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
  128. {          /* The -7 is for XXXXXXX */
  129.     int len = gp_file_name_sizeof - strlen(prefix) - 7;
  130.  
  131.     if (gp_gettmpdir(fname, &len) != 0)
  132.     *fname = 0;
  133.     else {
  134.     char *temp;
  135.  
  136.     /* Prevent X's in path from being converted by mktemp. */
  137.     for (temp = fname; *temp; temp++)
  138.         *temp = tolower(*temp);
  139.     if (strlen(fname) && (fname[strlen(fname) - 1] != '\\'))
  140.         strcat(fname, "\\");
  141.     }
  142.     strcat(fname, prefix);
  143.     strcat(fname, "XXXXXX");
  144.     mktemp(fname);
  145.     return gp_fopentemp(fname, mode);
  146. }
  147.  
  148.  
  149. /* Open a file with the given name, as a stream of uninterpreted bytes. */
  150. FILE *
  151. gp_fopen(const char *fname, const char *mode)
  152. {
  153.     return fopen(fname, mode);
  154. }
  155.